// 数据网关相关接口
import { servicesDataGateway as services, apiUrlDataGateway, servicesDataGatewayFee } from '../createServices';

// 供应商
export const supplier = {
  list: (params) => services.post('/std-supplier/supplier/page', { params, isLoading: true }),
  noPageList: () => services.get('/std-supplier/supplier/list', {}),
  add: (params) => services.post('/std-supplier/supplier', { params, isLoading: true }),
  update: (params) => services.put(`/std-supplier/supplier/${params.id}`, { params, isLoading: true }),
  detail: (id) => services.get(`/std-supplier/supplier/${id}`, {}),
  delete: (params) => services.del(`/std-supplier/supplier/${params.id}`, { isLoading: true }),
};

// 数据源管理
export const dataSource = {
  supplierList: () => services.get('/std-supplier/supplier/list', {}),
  list: (params) => services.post('/std-thirdInterface/thirdInterface/page', { params, isLoading: true }),
  add: (params) => services.post('/std-thirdInterface/thirdInterface', { params }),
  update: (params) => services.put(`/std-thirdInterface/thirdInterface/${params.id}`, { params }),
  detail: (id) => services.get(`/std-thirdInterface/thirdInterface/${id}`, {}),
  delete: (params) => services.del(`/std-thirdInterface/thirdInterface/${params.id}`, { isLoading: true }),
  listBySupplierId: (id) => services.get(`/std-thirdInterface/thirdInterface/list/${id}`, {}),
  dataSourceListBySupplier: (id) => services.get(`/std-thirdInterface/thirdInterface/list/${id}`, {}),
};

// 数据源类型 管理
export const dataSourceType = {
  list: (type) => services.get(`/std-thirdInterfaceType/thirdInterfaceType/list/${type}`, {}),
  add: (params) => services.post('/std-thirdInterfaceType/thirdInterfaceType', { params }),
  update: (params) => services.put(`/std-thirdInterfaceType/thirdInterfaceType/${params.code}`, { params }),
  delete: (code, type) => services.del(`/std-thirdInterfaceType/thirdInterfaceType/${code}/${type}`, {}),
};

// 扩展文件
export const file = {
  list: () => services.get('/std-encryptFile/encryptFile/list', {}),
  update: (params) => services.put(`/std-encryptFile/encryptFile/${params.id}`, { params }),
  delete: (id) => services.del(`/std-encryptFile/encryptFile/${id}`, {}),
  uploadUrl: `${apiUrlDataGateway}/std-encryptFile/encryptFile/upload`,
  getDownLoadUrl: (id) => `${apiUrlDataGateway}/std-encryptFile/encryptFile/download/${id}`,
};

// 数据源调用信息
export const call = {
  list: (params) =>
    services.post(`/std-thirdInterface/thirdInterface/callDetails/${params.id}`, { params, isLoading: true }),
};

// 内部接口管理
export const interfaceManage = {
  list: (params) => services.post('/std-innerInterface/innerInterface/page', { params, isLoading: true }), // 内部接口 分页
  innerInterface: (params) => services.post('/std-innerInterface/innerInterface', { params, isLoading: true }),
  add: (params) => services.post('/std-innerInterface/innerInterface', { params }),
  update: (params) => services.put(`/std-innerInterface/innerInterface/${params.id}`, { params }),
  delete: (params) => services.del(`/std-innerInterface/innerInterface/${params.id}`, {}),
  detail: (id) => services.get(`/std-innerInterface/innerInterface/${id}`, {}),
  onOff: (params) => services.post(`/std-innerInterface/innerInterface/onoffSwitch/${params.id}`, { params }), // 接口 发布/ 下线
};

// 历史版本
export const history = {
  list: (params) =>
    services.post(`/std-innerInterface/innerInterface/snapshotList/${params.id}`, { params, isLoading: true }),
  detail: (id) => services.get(`/std-innerInterface/innerInterface/snapshot/${id}`, { isLoading: true }),
  currVersion: (id) => services.get(`/std-innerInterface/innerInterface/currentVersion/${id}`, {}),
  switchVersion: (params) =>
    services.post(`/std-innerInterface/innerInterface/versionSwitch/${params.id}`, { params, isLoading: true }),
};

// 授权信息
export const authorizeInfo = {
  list: (params) => services.post(`/std-organAuth/appkey/list/${params.id}`, { params, isLoading: true }),
  organList: (params) => services.post('/std-organAuth/appkey/list', { params, isLoading: true }),
  getAppkeyByOrgan: (interfaceId, organId) =>
    services.get(`/std-organAuth/appkey/authList/${interfaceId}/${organId}`, {}),
  addAuthAppkey: (params) => services.put(`/std-organAuth/organAuthAppKey/${params.id}`, { params }),
  delete: (appKeyId, interfaceId) => services.del(`/std-organAuth/appkey/${appKeyId}/${interfaceId}`, {}),
};

// 数据库
export const database = {
  list: () => services.get('/bank/database-connection', {}),
  add: (params) => services.post('/bank/database-connection', { params }),
  update: (params) => services.put(`/bank/database-connection/${params.id}`, { params }),
  delete: (id) => services.del(`/bank/database-connection/${id}`, {}),
  test: (params) => services.options('/bank/database-connection/test', { params }),
};

// 接口调试
export const debug = {
  debug: (params) =>
    services.post(`/std-innerInterface/innerInterface/debug/${params.id}`, { params, isLoading: true }),
  downloadPdf: (id) => `${apiUrlDataGateway}/std-innerInterface/innerInterface/export/${id}`,
};
// 供应商账单
export const supplierBill = {
  list: (params) => servicesDataGatewayFee.get(`/std-thirdFee/thirdFee`, { params, isLoading: true }),
};

// 计费明细
export const feeDetail = {
  list: (params) => servicesDataGatewayFee.get(`/std-feeDetail/feeDetail`, { params, isLoading: true }),
  download: (params) => servicesDataGatewayFee.get(`/std-feeDetail/feeDetail/download`, { params, isLoading: true }),
};
